package work20241128;

import java.util.Arrays;

/**
 * @author zdl
 * @date 2024/11/28
 */
public class Demo10 {
    public static void main(String[] args) {
        //设计一个方法，删除指定下标的元素，要求从删除位置开始，之后的元素整体前移。
        int[] arr = {1,2,3,2,4};
        int[] newArr = remove(arr,3);
        System.out.println(Arrays.toString(newArr));

    }

    public static int[] remove(int[] arr,int num){
        int count = 0;
        int[] newArr = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]!= num){
                newArr[count++] = arr[i];
            }
        }
//        System.out.println(Arrays.toString(newArr));
        return newArr;
    }
}
